﻿using JmShared;
using SuperWebSocket.SubProtocol;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WebSocketServer.Filters;

namespace WebSocketServer.Commands
{
    [LogTimeCommandFilter(Order = 0)]
    public class VerifyResetPasswordMail : JsonSubCommand<JiveClientSession, VerifyMail>
    {
        protected override void ExecuteJsonCommand(JiveClientSession session, VerifyMail vm)
        {
            var result = DB.DbManager.StoreResetPasswordRequest(vm.Username);
            if (result.Success)
            {
                session.AppServer.TrySendEmail(string.Format("A password reset for your Jive Messenger account has been requested.\r\nCopy this validation code to verify your email address:\r\n{0}", result.Value),"Jive Messenger password reset",  vm.Username);
            }
            SendJsonMessage(session, new DatabaseQueryResponse(result.Success, result.StatusText));
        }
    }
}
